<template>
  <div @click="ative">
    <table border="1" class="agsbd-table" style="border-collapse: collapse;">
      <tr>
        <th v-for="item in tableColumns" :key="item.prop">{{ item.label }}</th>
      </tr>
      <tr v-for="item in tableData" :key="item.id">
        <td v-for="ite in tableColumns" :key="ite.prop">{{ item[ite.prop] }}</td>
      </tr>
    </table>
  </div>
</template>

<script>
import { getHandle } from '@/api'
export default {
  name: 'YlTable',
  props: {
    tableColumns: {
      type: Array,
      default: () => []
    },
    url: {
      type: String,
      default: ''
    },
    limit: {
      type: Number,
      default: 4
    },
    params: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      tableData: []
    }
  },
  created() {
    const params = { ...this.params, page: 1, limit: this.limit }
    getHandle(this.url, params).then((data) => {
      this.tableData = data.body.data
    })
  },
  methods: {
    ative() {
      this.$emit('click')
    }
  }
}
</script>

<style scoped>
.agsbd-table {
  width: 100%;
  color: #ffffff;
  border: solid 1px #155277;
}

.agsbd-table td {
  height: 40px;
  line-height: 40px;
  text-align: center;
}
.agsbd-table th {
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-weight: 400;
}
</style>
